"use server";

async function generateStreamPromises(count = 10) {
  if (count === 0) {
    return Promise.resolve(null);
  }

  const content = new Promise((resolve) => {
    setTimeout(() => {
      resolve(`这是第 ${count} 个测试`);
    }, 1000);
  });

  const ui = new Promise((resolve) => {
    setTimeout(() => {
      resolve({ type: "text" });
    }, 2000);
  });
  const next = await generateStreamPromises(count - 1);

  return Promise.resolve({ content, ui, next });
}

// 服务端的 action 函数。从 llm 获取数据返回
export async function send({ messages }) {
  console.log("got action");
  return generateStreamPromises();
}
